#include "StdAfx.h"
#include "MeetingCollection.h"


MeetingCollection::MeetingCollection(void)
{
	meetingIdSeq = 0;
}


MeetingCollection::~MeetingCollection(void)
{
}

bool MeetingCollection::hasMeeting(const string& title)
{
	if( meetingDict.find(title) == meetingDict.end() )
		return false;
	else
		return true;
}//modify

void MeetingCollection::addMeeting(string title, User& inviter, User& invitee, Interval interval)
{
	Meeting meeting( getMeetingIdSeq(), title, inviter, invitee, interval );		//a new meeting

	meetings.insert( map<int,Meeting>::value_type(getMeetingIdSeq(), meeting) );	
	meetingDict.insert( map<string,int>::value_type(title, getMeetingIdSeq()) );	//insert into the meetingCollection

	meetingIdSeq++;		//update the number of the meetings

	return;
}//modify

Meeting& MeetingCollection::getMeetingById(int id)
{
	return meetings.find(id)->second;
}

Meeting& MeetingCollection::getMeetingByTitle(const string& title)
{
	return meetings.find(getIdByTitle(title))->second;
}

int MeetingCollection::getIdByTitle(const string& title)
{
	return meetingDict.find(title)->second;
}

int MeetingCollection::getMeetingIdSeq()
{
	return meetingIdSeq;
}

bool MeetingCollection::deleteMeetingById(int id)
{

	string title = getMeetingById(id).getTitle();
	meetings.erase(id);
	meetingDict.erase(title);

	return true;
}

map<int,Meeting> & MeetingCollection::getMeetings()
{
	return meetings;
}
